import 'package:chat/pages/Circle/circle/index.dart';
import 'package:chat/pages/chat/chat/index.dart';
import 'package:chat/pages/friend/friend/index.dart';
import 'package:chat/pages/person/person/index.dart';
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';

class MainController extends GetxController {
  MainController();

  // 当前页面的索引
  var currentIndex = 0.obs;
  final PageController pageController = PageController();

  final List<Widget> pageList = const [ChatPage(), FriendPage(), CirclePage(), PersonPage()];

  // 切换底部导航栏
  void changeTab(int index) {
    currentIndex.value = index;
    pageController.jumpToPage(index);
  }

  void onPageChanged(int index) {
    currentIndex.value = index;
  }

  _initData() {
    update(["main"]);
  }

  void onTap() {}

  @override
  void onInit() {
    super.onInit();
    // permanent: true 常驻内存
    Get.put(ChatController(), permanent: true);
    Get.put(FriendController(), permanent: true);
    Get.put(CircleController(), permanent: true);
    Get.put(PersonController(), permanent: true);
  }

  @override
  void onReady() {
    super.onReady();
    _initData();
  }

  // @override
  // void onClose() {
  //   super.onClose();
  // }
}
